package com.note7_6;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Company implements Serializable{

	//公司有公司名称，注册地址，电话，经营范围等属性（动态输入），公司有很多员工（用List存储，作为公司的一部分）
	//公司有招聘员工（要求工号不能重复），有输出员工信息，以及辞退员工，和统计公司人数的方法用oo的思想模拟，
	private String name;
	private String location;
	private long phone;
	private String business;
	private List<Person> person = new ArrayList<Person>();
	private static final long serialVersionUID = 1L;
	
//	public Company(){
//		
//	}
	
	public Company(String name,String location,long phone,String business){
		this.name = name;
		this.location = location;
		this.phone = phone;
		this.business = business;
	}
	
	//检查工号，若有相同则更改员工工号
	public void repettion(Person person){
		for(Person p:this.person){
			if(person.getNumber() == p.getNumber()){
				person.setNumber(person.getNumber()+1);	//工号重复时加1
				repettion(person);
			}
		}
	}
	
	//招聘员工（要求工号不能重复）
	public int addPerson(Person person){
		repettion(person);
		this.person.add(person);
		return person.getNumber();
	}

	//获取指定工号在list中的位置
	public int getPersonIndexOf(int number){
		for(int i = 0;i < this.person.size();i++){
			Person p = this.person.get(i);
			if(p.getNumber() == number){
				return i;
			}
		}
		return -1;
	}
	//辞退员工
	public void delete(int number){
		int flag = getPersonIndexOf(number);
		if(flag != -1){
			this.person.remove(flag);
		}
	}
	
	//公司人数
	public int number(){
		return this.person.size();
	}
	
	public List<Person> getPerson() {
		return person;
	}
	public void setPerson(List<Person> person) {
		this.person = person;
	}

	@Override
	public String toString() {
		return "Company [name=" + name + ", location=" + location + ", phone=" + phone + ", business=" + business
				+ ", person=" + person + "]";
	}

	
	
	
}
